﻿using JustMetClient.Commons;
using JustMetClient.Modules.LoginModule;
using JustMetClient.Socket.Models;
using JustMetClient.Tools;
using Azylee.Core.DataUtils.CollectionUtils;
using Azylee.Core.ThreadUtils.SleepUtils;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace JustMetClient.Modules.SocketModule
{
    public class SocketStatusEvent
    {
        public static void Update(object sender, SocketStatusArgs status)
        {
            switch (status.Status)
            {
                case SocketStatus.已连接:
                case SocketStatus.已开始:
                    if (!R.Socket.IsConnect)
                    {
                        R.Socket.IsConnect = true;
                        //SocketSendQueue.AddToQueue("22", R.Computer.GetIPAddress() + "&" + R.Computer.GetMacAddress() + "&" + R.Version + "&" + R.Computer.GetUserName(), 0);
                        R.NetInfo.Refresh(status.LocalIP);


                        Task.Factory.StartNew(() =>
                        {
                            if (LoginHelper.AutoLogin())
                            {
                                R.Toast.AutoShow("提示", "网络认证成功：" + R.UserName);
                            }
                        });
                    }
                    break;
                default:
                    R.Socket.IsConnect = false;
                    break;
            }
            R.MainUI.UpdateConnStatus(R.Socket.IsConnect);
        }
    }
}
